//自定义正则表达示验证方法 
$.validator.addMethod("checkPhone", function(value, element, params) {
	var phoneReg = /^(13|15|18)\d{9}$/;
	return this.optional(element) || (phoneReg.test(value));
}, "手机格式错误");

$.validator.addMethod("checkId", function(value, element, params) {
	var idReg = /^(13|15|18)\d{9}$/;
	return this.optional(element) || (idReg.test(value));
}, "身份证格式错误");

$(function() {
	$('#signupForm').validate({
		//失去焦点时验证
		onfocusout: function(element) {
			$(element).valid();
		},
		rules: {
			txtNo: {
				required: true,
				rangelength: [6, 12]
			},
			txtPwd: {
				required: true,
				rangelength: [6, 12]
			},
			txtConfirmPwd: {
				required: true,
				equalTo: "#txtPwd"
			},
			txtName: {
				required: true,
				rangelength: [2, 6]
			},
			txtId: {
				required: true,
				checkPhone: true
			},
			txtPhone: {
				required: true,
				checkId: true
			}
		},
		messages: {
			txtNo: {
				required: "账号必填",
				rangelength: "账号的长度在6到12位之间"
			},
			txtPwd: {
				required: "密码必填",
				rangelength: "密码的长度在6到12位之间"
			},
			txtConfirmPwd: {
				required: "确认密码必填",
				equalTo: "两次输入的密码不一致"
			},
			txtName: {
				required: "姓名必填",
				rangelength: "姓名的长度在2到6位之间"
			},
			txtId: {
				required: "身份证必填",
				checkPhone: "身份证格式错误"
			},
			txtPhone: {
				required: "手机号必填",
				checkId: "手机格式错误"
			}
		}
	});
	//自动触发账号文本框的focus事件
	$('#txtNo').trigger('focus');
	$('#txtNo,#txtPwd,#txtPwd,#txtConfirmPwd,#txtId,#txtName,#txtPhone').blur(function() {
		$.validate_form();
	})
});